//
//  ADBaseTableViewController.swift
//  myBlog
//
//  Created by mac2014 on 16/3/21.
//  Copyright © 2016年 AD. All rights reserved.
//

import UIKit

class ADBaseTableViewController: UITableViewController {
    
    var userIsLogin = ADUserAcountViewModel.sharedInstance.isLogin
    
    //代理设置
    override func loadView() {
        //四个控制器每次切换都会调用这个方法
        userIsLogin ? super.loadView() : setupVistorView()
    }
    
    func setupVistorView() {
        self.view = visitorView
        //设置代理
        visitorView.delegate = self
        
        if self is ADHomeViewController {
            visitorView.startRotate()
        }else if self is ADMassageController {
            visitorView.setupVisitorView("visitordiscover_image_message", massage: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
        }else if self is ADDiscoverController {
            visitorView.setupVisitorView("visitordiscover_image_message", massage: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
        }else if self is ADProfileController {
            visitorView.setupVisitorView("visitordiscover_image_profile", massage: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        }
        
        //设置导航栏按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewDidClickRegisterBtn")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewDidClickLoginBtn")

    }
    
    //mark - 懒加载访客视图
    lazy var visitorView: ADVisitorView = ADVisitorView()

}

// MARK: - 实现visitorView的代理方法
extension ADBaseTableViewController: ADVisitorViewDelegate {
    
    func visitorViewDidClickRegisterBtn() {
        let networkTool = ADNetWorkingTool.sharedInstance
            }
    
    func visitorViewDidClickLoginBtn() {
        //弹出webview
        let webVC = AuthController()
        
        presentViewController(UINavigationController(rootViewController: webVC), animated: true, completion: nil)
    }
}
